//
//  UIImage+extension.swift
//  添加图片
//
//  Created by 雄 on 15/7/25.
//  Copyright © 2015年 雄. All rights reserved.
//

import UIKit

extension UIImage {

///  将图片缩放到指定宽度
func scaleToWidth(width: CGFloat) -> UIImage {
    
    let h = size.height * width / size.width
    
    let s = CGSize(width: width, height: h)
    // 图像渲染上下文
    UIGraphicsBeginImageContext(s)

    drawInRect(CGRect(origin: CGPointZero, size: s))
    
    let img = UIGraphicsGetImageFromCurrentImageContext()
    
    UIGraphicsEndImageContext()
    
    return img
}

}